package com.study.zk.lock.zk;

import org.I0Itec.zkclient.IZkDataListener;
import org.I0Itec.zkclient.ZkClient;

/**
 * @author: chenhs
 * @date: Created in 9:55 2020/2/4
 **/
public class ZkWatcherDemo {

    public static void main(String[] args) {

        ZkClient client = new ZkClient("localhost:2181");
        client.setZkSerializer(new MyZkSerializer());

        //订阅
        client.subscribeDataChanges("/mike/a", new IZkDataListener() {
            @Override
            public void handleDataDeleted(String dataPath) throws Exception {
                System.out.println("---------------收到节点被删除了--------------");
            }

            @Override
            public void handleDataChange(String dataPath, Object data) throws Exception {
                System.out.println("---------------收到节点数据变化：" + data + "--------------");
            }
        });


        try {
            Thread.sleep(1000 * 60 * 2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }

}
